package com.tsunami.authority.enums.admin;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.tsunami.base.BaseEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * @author lx
 * @since 2023/9/21 17:47
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "授权类型-枚举")
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum EmpowerType implements BaseEnum {
    /**
     * W="week"
     */
    W("周卡", "W"),
    /**
     * M="mouth"
     */
    M("月卡", "M"),
    /**
     * Y="year"
     */
    Y("年卡", "Y"),
    ;
    @Schema(description = "描述")
    private String desc;
    @Schema(description = "编码")
    private String code;

    public static EmpowerType match(String val, EmpowerType def) {
        for (EmpowerType enm : EmpowerType.values()) {
            if (enm.name().equalsIgnoreCase(val)) {
                return enm;
            }
        }
        return def;
    }

    public static EmpowerType get(String val) {
        return match(val, null);
    }

    public boolean eq(String val) {
        return this.name().equalsIgnoreCase(val);
    }

    public boolean eq(EmpowerType val) {
        if (val == null) {
            return false;
        }
        return eq(val.name());
    }

    @Override
    public String getCode() {
        return this.code;
    }

    @Override
    public String getDesc() {
        return this.desc;
    }

    public static EmpowerType getEnum(String code) {
        for (final EmpowerType item : EmpowerType.values()) {
            if (item.code.equals(code)) {
                return item;
            }
        }
        return null;
    }

}
